//
//  DBYSubjectViewController.m
//  MemoryTravel
//
//  Created by dllo on 15/12/28.
//  Copyright © 2015年 fcx. All rights reserved.
//

#import "DBYSubjectViewController.h"

@interface DBYSubjectViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) NSMutableArray *placeArray;
@property (nonatomic, retain) NSMutableArray *nameArray;
@end

@implementation DBYSubjectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.placeArray = [NSMutableArray array];
    self.nameArray = [NSMutableArray array];
    
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Width, Height - 80) style:UITableViewStylePlain];
    [self.view addSubview:self.myTableView];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.myTableView registerClass:[DBYSubjectTableViewCell class] forCellReuseIdentifier:@"cell"];

    [self getAFNetWorkingData];
    
    // Do any additional setup after loading the view.
}

- (void)getAFNetWorkingData{
    
    NSString *url_string = [NSString stringWithFormat:@"http://chanyouji.com/api/articles.json?destination_id=%@&page=1", self.dURL];
    [AppTools getDataWithUrlStr:url_string andBlock:^(id result) {
    
    
     NSMutableArray *array = [NSMutableArray arrayWithArray:result];
        for (NSMutableDictionary *dic in array) {
            DBYSubjectModel *subjectModel = [[DBYSubjectModel alloc] init];
            [subjectModel setValuesForKeysWithDictionary:dic];
            
            if (![self.nameArray containsObject:subjectModel.name]) {
                [self.placeArray addObject:subjectModel];
                [self.nameArray addObject:subjectModel.name];
            }
            
            
        }
        [self.myTableView reloadData];
        
    }];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSLog(@"%ld",self.placeArray.count);
    return self.placeArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdenrifier = @"cell";
    
    DBYSubjectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdenrifier];
    
    DBYSubjectModel *subjectModel = [self.placeArray objectAtIndex:indexPath.row];
    cell.aModel = subjectModel;
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 240 ;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
